import { VideoType, VideoTypeConfig } from "./video-type";
import { getVideoType } from "./videos";

export class Rental {
  title: string;
  days: number;
  type: VideoType;

  constructor(title: string, days: number) {
    this.title = title
    this.days = days
    this.type = getVideoType(title)
  }

  getConfig(title: string) {
    const type = getVideoType(title) || VideoType.REGULAR;
    const config = VideoTypeConfig[type];
    return config;
  }
  applyGracePeriod(amount: number, grace: number): number {
    return this.days > grace ? amount * (this.days - grace + 1) : amount;
  }
  calcFee() {
    const config = this.getConfig(this.title);
    return this.applyGracePeriod(config.fee, config.grace)
  }

  isRegularVideo(title: string) {
    return getVideoType(title) === VideoType.REGULAR;
  }

  calcPoint() {
    const type = getVideoType(this.title) || VideoType.REGULAR
    const config = VideoTypeConfig[type]
    return this.isRegularVideo(this.title) ? this.applyGracePeriod(config.point, config.grace) : 1
  }


}